package com.mm.cme.kotlin_001.level03_object_oriented_program.interface_and_abstract

import com.mm.cme.kotlin_001.utils.pl

/**
 * Descriptions：接口以及抽象类
 * <p>
 * Author：ChenME
 * Date：2017/7/17
 * Email：ibelieve1210@163.com
 */

/**
 * 输入设备
 */
interface InputDevice {
    fun input(event: Any)
}

/**
 * USB输入设备
 */
interface USBInputDevice : InputDevice

/**
 * 低功耗输入设备
 */
interface BLEInputDevice : InputDevice

/**
 * 光电鼠标
 */
interface OpticalMouse

abstract class USBMouse(val name: String) : USBInputDevice, OpticalMouse {
    override fun input(event: Any) {

    }

    override fun toString(): String {
        return name
    }
}

class LogitechMouse : USBMouse("罗技鼠标")

class Computer {

    fun addUSBInputDevice(inputDevice: USBInputDevice) {
        pl("add USB input device -> $inputDevice.")
    }

    fun addBLEInputDevice(inputDevice: BLEInputDevice) {
        pl("add BLE input device -> $inputDevice.")
    }

    fun addInputDevice(inputDevice: InputDevice) {

        when (inputDevice) {
            is USBInputDevice -> addUSBInputDevice(inputDevice)
            is BLEInputDevice -> addBLEInputDevice(inputDevice)
            else -> throw IllegalArgumentException("输入设备不支持！")
        }
    }
}

fun main(args: Array<String>) {
    val computer = Computer()
    computer.addInputDevice(LogitechMouse())
}